/*
  ==============================================================================

    DelayLine.h
    Created: 30 Nov 2014 6:09:37pm
    Author:  Alistair Barker

  ==============================================================================
*/

#ifndef DELAYLINE_H_INCLUDED
#define DELAYLINE_H_INCLUDED

#include "../JuceLibraryCode/JuceHeader.h"

enum interpolationType {
    linear,
    allpass,
    glissableAllpass
};

class AllPassReader
{
public:
    AllPassReader(AudioSampleBuffer &buffer);
    ~AllPassReader();
    void setDelayLength(double delayLength, int writePointer);
    void checkReadbuffers();
    double calculateOutput ();
    void advanceReader();
    
private:
    double lastSample;
    double fractDelay;
    int readPointer;
    AudioSampleBuffer* delayBuffer;
    
};


class DelayLine
{
public:
    DelayLine();
    
    double read();

    void write(double inputSample);
    
    void setDelay (double delayInSamples);
    void setDelayWithGliss(double delayInSamples, double timeInSecs, double fs);
    
    double getDelayLength() {return delayLengthSamples;};

private:
        
    AudioSampleBuffer delayBuffer;
    
    int writePointer;

    AllPassReader *newAllPassReader;
    AllPassReader *oldAllPassReader;
    
    double delayLengthSamples;
    
    int crossfadeCount = 0;
    const int crossfadeLength = 16;
    
    double glissandoIncrement;
    double glissandoTarget;

};


#endif  // DELAYLINE_H_INCLUDED
